package com.li.consumer;

import com.li.config.RabbitmqConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Slf4j
public class MessageConsumer {

    @RabbitHandler
    @RabbitListener(queues = RabbitmqConfig.dlQueue)
    public void consume(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("消费啦！！,--------消费时间:{}", df.format(new Date()));
        System.out.println(message);
    }
}
